package com.hq.ims.data.aop;

import com.hq.authority.utils.AppUtils;
import com.hq.ims.data.entity.User;
import com.hq.ims.data.utils.CurThreadLocalUtil;
import com.hq.ims.data.utils.ErrMsgConstant;
import com.hq.utils.util.BooleanUtils;
import com.hq.utils.util.JsonUtils;
import com.hq.utils.util.ObjectUtils;
import com.hq.web.conf.bean.UserAttribute;
import com.hq.web.inf.user.ITokenUserInfo;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 初始化aop
 * 描述: 第一个进入的切面初始化ThreadStore
 */
@Order(2)
@Aspect
@Component
@Slf4j
public class PlatformUserValidAspect {
    @Resource
    private UserAttribute userAttribute;

    @Pointcut(value = "execution(* com.hq.ims.platform.controller.*.*(..))")
    private void controllerAspect() {
    }

    @Before(value = "controllerAspect()")
    public void doBefore(JoinPoint point) throws Throwable {
        ITokenUserInfo currentUser = AppUtils.getCurrentUser();
        ObjectUtils.isNullThrow(currentUser, ErrMsgConstant.USER_NOT_AUTH_OPERATE_PLATFORM_DATA);
        User user = (User) currentUser;
        BooleanUtils.isFalseThrow(user.getIsAdmin(), ErrMsgConstant.USER_NOT_AUTH_OPERATE_PLATFORM_DATA);
    }

    @After(value = "controllerAspect()")
    public void doAfter(JoinPoint point) {

    }
}
